package com.pb.infra.taskManage.controller;

import com.pb.infra.oth.entity.common.Page;
import com.pb.infra.oth.entity.common.Result;
import com.pb.infra.oth.util.Constant;
import com.pb.infra.oth.util.SysLog;
import com.pb.infra.taskManage.service.TaskRelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 *任务依赖关系
 * @author liaohaoyuan
 * @date 20210501
 */
@Slf4j
@RestController
@RequestMapping("v1/taskManage/taskRel")
public class TaskRelController {

    /**
     * 业务逻辑对象
     */
    @Resource
    private TaskRelService taskRelService;

    /**
     * 日志操作表
     */
    private static final String TABLE_NAME = "Ma_Job_Rely_Cfg";

    /**
     * 日志操作功能名
     */
    private static final String OPERATION_MENU = "任务依赖关系";

    /**
     * 查询分页数据
     * @param map 请求参数
     * @param page 页码
     * @return Result 返回数据
     */
    @GetMapping(value = "select")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.QUERY, menuName = OPERATION_MENU)
    public Result select(@RequestParam Map<String, Object> map, Page page) {
        return taskRelService.select(map, page);
    }

    /**
     * 获取配置表左表数据
     * @param paramMap 请求参数
     * @return Result 返回数据
     */
    @GetMapping("getLeftTableData")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.QUERY, menuName = OPERATION_MENU)
    public Result getLeftTableData(@RequestParam Map<String, Object> paramMap){
        return taskRelService.getLeftTableData(paramMap);
    }

    /**
     * 获取配置表右表数据
     * @param paramMap 请求参数
     * @return Result 返回数据
     */
    @GetMapping("getRightTableData")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.QUERY, menuName = OPERATION_MENU)
    public Result getRightTableData(@RequestParam Map<String,Object> paramMap){
        return Result.ok(taskRelService.getRightTableData(paramMap));
    }

    /**
     * 保存配置表右表数据
     * @param list 请求参数
     * @return Result 返回数据
     */
    @PostMapping(value = "saveTables")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.ADD, menuName = OPERATION_MENU)
    public Result saveTables(@RequestBody List<Map<String,Object>> list)
    {
        taskRelService.saveTables(list);
        return Result.OK_EMPTY;
    }

}
